// polygon defination 


#include "Polygon.h"



Polygon::Polygon(){

   points = new Matrix(1,1);
}


Polygon::Polygon(const MyDisplay &another):Line(another){

   //Polygon();   
   points = new Matrix(1,1);

}

Polygon::Polygon(const Matrix &R){


   points = new Matrix(R);
     
}


Polygon::Polygon(const char *fileName,const MyDisplay &another):Line(another){

     points = new Matrix(fileName);    
 
      
}


Polygon::~Polygon(){

}


bool Polygon::draw(){

  int i;

  //cout<<"Inside Polygon drawing"<<endl;
  //cout<<"###############################"<<endl; 
  
   for(i =1;i< points->numRows();++i){
    //    cout<<"X"<<i-1<<"  "<<(*points)[i-1][0]<<"   Y"<<i-1<<"  "<<(*points)[i-1][1]<<"TO " <<"X"<<i<<"  "<<(*points)[i][0]<<"   Y"<<i<<"  "<<(*points)[i][1]<< endl;  
        drawLine((double)(*points)[i-1][0],(double)(*points)[i-1][1],(double)(*points)[i][0],(double)(*points)[i][1]);
    }	
	
  //cout<<"The Last Element :X0"<<"  "<<(*points)[0][0]<<"   Y0"<<"  "<<(*points)[0][1]<<" TO  X"<<i-1<<"  "<<(*points)[i-1][0]<<"   Y"<<i-1<<"  "<<(*points)[i-1][1]<<endl;    
  drawLine((double)(*points)[0][0],(double)(*points)[0][1],(double)(*points)[i-1][0],(double)(*points)[i-1][1]);
  
  
return true;
}




bool Polygon::draw(const Matrix &T){

    (*points) = T;
    
    draw();
    
   return true;
}

bool Polygon::draw(const char *fileName){

     Matrix T(fileName);
     
     (*points) = T;
     
//     points->disp();
     
     draw();
     
     return true;
}

bool Polygon::change(const int x,const int y){

       for(int i = 0;i<points->numRows();++i){
       
          (*points)[i][0] = (*points)[i][0] + (double)x;
	  (*points)[i][1] = (*points)[i][1] + (double)y;
	  
        }
    

}
